package com.cosmoplat.mom.iot.client.api.response;

import com.cosmoplat.mom.iot.client.exception.IotClientException;
import lombok.Data;

import java.util.function.Function;

/**
 * @author yotta
 * @date 2025/6/16
 */
@Data
public class IotResponse<T> {

    private T result;
    private Boolean success;
    private String code;
    private String message;

    public T getResultIfSuccess() {
        if (!success) {
             throw new IotClientException(message);
        }
        return result;
    }

    public <R> R getResultIfSuccess(Function<T, R> mapping) {
        if (!success) {
             throw new IotClientException(message);
        }
        return mapping.apply(result);
    }


}
